package com.mmy.dao.car;

import java.util.List;

import javax.transaction.Transactional;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import com.mmy.domain.car.TCarBase;

public interface TCarBaseRepository extends JpaRepository<TCarBase, Integer> {

	/**
	 * 获得最大房间编号
	 * 
	 * @return 返回值说明 最大ID
	 * @author 创建人 dingxd
	 * @date 创建日期 2020.11.17
	 */
	@Query(value = "SELECT MAX(iCarID) FROM tCarBase WHERE LEFT(iCarID,2) = RIGHT(YEAR(NOW()),2)", nativeQuery = true)
	Object getMaxCarID();

	/*
	 * 根据id删除
	 */
	@Transactional
	@Modifying
	@Query(value = "delete from tCarBase where tCarBase.iCarID in (:lstCarID)", nativeQuery = true)
	void delCarBase(@Param("lstCarID") List<Integer> lstCarID);

	/*
	 * 根据id查找
	 */
	@Query(value = "select *  from tCarBase where iCarID = :iCarID", nativeQuery = true)
	TCarBase findByCarID(@Param("iCarID") int iCarID);

	/*
	 * 新增id
	 */

	@Transactional
	@Modifying
	@Query(value = "INSERT INTO tCarBase(iCarID, iOrgID, iTypeID, cCarNum, cCarBrand, cDriverName, cDriverPhone, bSafeYear, cCarSafe, cCarYear, cPower, cPhotoPath, dCreateDate, cCreator, dModifyDate, cReviser, cMemo, cSpare1, cSpare2, cSpare3, cSpare4, cSpare5) VALUES (:carID, 0, 0, NULL, NULL, NULL, NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)", nativeQuery = true)
	void save(@Param("carID") int carID);

}
